﻿using Microsoft.AspNetCore.Mvc;
using XsqTech.SmartOA.Dtos.DTO;
using XsqTech.SmartOA.Dtos.XSPDto.FromDto;
using XsqTech.SmartOA.IService;
using XsqTech.SmartOA.Service;
using XsqTech.SmartOA.Service.DTO;

namespace XsqTech.SmartOA.Application.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        IDepartmentService _departmentService;

        public DepartmentController(IDepartmentService departmentService)
        {
            _departmentService = departmentService;
        }
        /// <summary>
        /// 部门分页显示
        /// </summary>
        /// <param name="departmentPageDto"></param>
        /// <returns></returns>
        [HttpGet("DShow")]
        public IActionResult DShow([FromQuery] DepartmentPageDto departmentPageDto)
        {
            var ls = _departmentService.DShow(departmentPageDto);
            return Ok(new { data = ls, msg = "显示成功!" });
        }
        /// <summary>
        /// 部门树形的显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDepartTree()
        {
            return Ok(_departmentService.GetDepartTree());
        }
        /// <summary>
        /// 部门修改返填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public IActionResult BackUpt(Guid id)
        {
            return Ok(new { data = _departmentService.GIt(id) });
        }
        /// <summary>
        /// 部门修改
        /// </summary>
        /// <returns></returns>
        [HttpPut("Update")]
        public IActionResult Update(UptDepartmentsDto uptDepartmentsDto)
        {
            //模型验证
            if (!ModelState.IsValid)
            {
                return Ok("数据未传入");
            }
            else
            {
                MsgResponse<UptDepartmentsDto> responseModel = _departmentService.Update(uptDepartmentsDto);
                return Ok(responseModel);
            }
        }
        /// <summary>
        /// 给部门添加用户
        /// </summary>
        /// <param name="addDepartmentsUsersDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddDepartmentsUser(AddDepartmentsUsersDto addDepartmentsUsersDto)
        {
            return Ok(new { data = _departmentService.AddDepartmentsUser(addDepartmentsUsersDto) });
        }
        /// <summary>
        /// 部门添加用户
        /// </summary>
        /// <param name="addDepartmentsUsersDto"></param>
        /// <returns></returns>
        [HttpPost("1")]
        public IActionResult AddDepartmentsUser1(AddDepartmentsUsersDto addDepartmentsUsersDto)
        {
            return Ok(_departmentService.AddDepartmentsUser1(addDepartmentsUsersDto));
        }
        /// <summary>
        /// 部门添加
        /// </summary>
        /// <returns></returns>
        [HttpPost("Add")]
        public IActionResult Add(AddDepartmentsDto AddDepartmentsDto)
        {
            if (!ModelState.IsValid)
            {
                return Ok("数据未传入");
            }
            else
            {
                MsgResponse<AddDepartmentsDto> responseModel = _departmentService.Add(AddDepartmentsDto);
                return Ok(responseModel);
            }
        }
        /// <summary>
        /// 部门的删除
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult Del(string id)
        {
            var data = _departmentService.Del(id);
            return Ok(data);
        }
        [HttpDelete("AllDelete")]
        public IActionResult AllDepartmentDelete(List<DepartmentDto> dto)
        {
            return Ok(_departmentService.AllDepartmentDelete(dto));
        }
    }
}
